import {GetUserTravels, UserLottery, UserTodayLotteryCount} from "../../model/travels";

Page({
    data: {
        travelsList: [],
        startMaskShow: false,
        last_count: 0
    },
    onLoad: function (options) {

    },
    onShow() {
        this.getTravels()
        this.getUserLottery()
    },
    getTravels() {
        GetUserTravels().then(res => {
            res.pop()
            this.setData({
                travelsList: res
            })
        })
    },
    getLottery() {
        UserLottery().then(res => {
            this.setData({
                last_count: res.count - res.used_count
            })
        })
    },
    getUserLottery() {
        UserTodayLotteryCount().then(res => {
            if (res.count == 0) {
                this.setData({
                    startMaskShow: true
                })
            } else {
                this.getLottery()
            }
        })
    },
    onItemTap(e) {
        const item = e.currentTarget.dataset.item
        console.log(item)
        wx.navigateTo({
            url: `/pages/intangible-detail/index?category=${item.category}`
        })
    },
    onCloseMask() {
        this.setData({
            startMaskShow: false
        })
    },
    onLotteryClick() {
        setTimeout(() => {
            this.setData({
                startMaskShow: false
            })
            this.getUserLottery()
        }, 1500)
    }
});
